<?php
require_once '../../ptnhuan-web1/libraries/utilites/functions.php';
$path = "../../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
$rating = NULL;
?>
<form method="POST" align="center">
    <input type="text" name="rating">
    <input type="submit" name="submit" value="Search">
</form>
<?php if (isset($_POST['submit'])): ?>
    <?php $rating = (double) $_POST['rating']; ?>
<?php endif; ?>
<?php
// for ($i = 0; $i < count($films); $i++){
////    $film = explode(";", $films[$i]);
////    $img = trim($film[0]);
////    echo "<img src = '"."../../ptnhuan-web1/public/images/films/".$img."'>".$film[1].' '.$film[2]."<br>";
//    
//}
?>

<?php
foreach ($films as $film):?>
<?php $film = trim($film);
          if(!empty($film)):?>
    <?php $mfil = explode(";", $film);
    $mfile = trim($mfil[1]);
    ?>
    <?php if (empty($rating)): ?>
        <?php if (isset($mfil[2]) || isset($mfil[3])): ?>
            <img src = '../../ptnhuan-web1/public/images/films/<?php echo $mfile ?>'> 
            <?php echo $mfil[2] ?>
            <?php echo $mfil[3] ?>
            <br>
        <?php endif; ?>
    <?php else: ?>
        <?php if (isset($mfil[2]) || isset($mfil[3])): ?>
            <?php if ($rating <= (double) $mfil[3]): ?>
                <img src = '../../ptnhuan-web1/public/images/films/<?php echo $mfile ?>'> 
                <?php echo $mfil[2] ?>
                <?php if (!empty($mfil[3])) echo $mfil[3] ?>
                <br>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>     
  <?php endif; ?> 
<?php endforeach; ?>

